package com.luhy.listener;

import com.luhy.pojo.Order;
import com.luhy.service.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class OrderDeadLetterListener {

    Logger log = LoggerFactory.getLogger(OrderDeadLetterListener.class);

    @Autowired
    private OrderService orderService;

    @RabbitListener(queues = "qd")
    public void onMessage(String orderNo) {
        Order order = orderService.selectByOrderNo(orderNo);
        if (order.getStatus() != 0) {
            log.info("订单状态发生改变，不能进行取消！");
            return;
        }
        orderService.updateStatus(orderNo, 4);
        log.info("订单{}已取消", orderNo);
    }
}
